package com.rc.web.controller;



import com.mybatisflex.core.paginate.Page;
import com.rc.common.annotate.WithoutTenant;
import com.rc.pojo.dto.comment.CommentAddDTO;
import com.rc.pojo.dto.comment.CommentPageQuery;
import com.rc.pojo.vo.comment.CommentPageVO;
import com.rc.pojo.vo.comment.CommentVO;
import com.rc.web.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.hibernate.validator.constraints.Range;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 评论表 控制层。
 *
 * @author sym
 * @since 2024-05-26
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论")
@RequiredArgsConstructor
@Validated
public class CommentController {
    private final CommentService commentService;

    @PostMapping
    @ApiOperation("发布评论")
    @WithoutTenant
    public void add(@RequestBody CommentAddDTO dto) {
        commentService.add(dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除评论")
    @WithoutTenant
    public void deletedOneById(@PathVariable Long id){
        commentService.deletedOneById(id);
    }

    @GetMapping("/{id}")
    public CommentVO getOneById(@PathVariable @ApiParam("评论id") Long id){
        return commentService.getOneById(id);
    }

    @GetMapping("/page")
    @ApiOperation("农场管理员分页查看农场评论")
    public Page<CommentPageVO> getPage(CommentPageQuery dto){
        return commentService.getPage(dto);
    }

    @GetMapping("/list")
    @ApiOperation("评论列表")
    @WithoutTenant
    public List<CommentVO> actlist(@NotNull @ApiParam("对应表id") Long itemId,
                                   @NotNull @Range(min = 0, max = 2) @ApiParam("查询类型：0农庄 1活动 2认养") Integer type) {
        return commentService.listByType(itemId, type);
    }

    @GetMapping("viewsAdd/{id}")
    @ApiOperation("评论浏览量+1")
    @WithoutTenant
    public void viewsAdd(@PathVariable @ApiParam("评论id") Long id){
        commentService.viewsAdd(id);
    }
}
